package com.sl.au.service.impl;

import com.sl.au.entity.AfterSaleExperience;
import com.sl.au.repository.AfterSaleExperienceRepository;
import com.sl.au.service.AfterSaleExperienceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("AfterSaleExperienceService")
@Transactional
public class AfterSaleExperienceServiceImpl extends BaseServiceImpl implements AfterSaleExperienceService {

    @Autowired
    AfterSaleExperienceRepository afterSaleExperienceRepository;
    @Override
    public List<AfterSaleExperience> getPage(int start, int length, String key, String orderName, String dir) {
        Page<AfterSaleExperience> pages=null;
        Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"createTime");
        pages=afterSaleExperienceRepository.findAll(pageable);
        return pages.getContent();
    }
    @Override
    public List<AfterSaleExperience> getAfterSaleExperience(int start, int length,String key,String orderName ,String dir){
        Page<AfterSaleExperience> pages = null;
        Pageable pageable=new PageRequest(start/length,length, Sort.Direction.DESC,"id");
        pages = afterSaleExperienceRepository.getAfterSaleExperienceTitle(key, pageable);

        return pages.getContent();
    }
    @Override
    public List<AfterSaleExperience> getIndex(int start, int length,String key,String orderName ,String dir){
        Page<AfterSaleExperience> pages = null;
        Pageable pageable=new PageRequest(start/length,length, Sort.Direction.DESC,"id");
        pages = afterSaleExperienceRepository.getAfterSaleExperienceTitle(key, pageable);
        return pages.getContent();
    }
    @Override
    public AfterSaleExperienceRepository getRepository() {
        return afterSaleExperienceRepository;
    }

}